<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
  
  //练习二：传入宽高，返回面积
  function getRectangleArea(width,height){
    var area=width*height
    return area
  }
  
  var area=getRectangleArea(10,10)
  console.log(area)
  function getCircleArea(radius){
    return (Math.PI*radius*radius).toFixed(2)//保留两位小数
  }
  var area3=getCircleArea(6)
  console.log(`圆的面积是${area3}`)
  //计算1~n的数字和
  
  function sumN(n){
    if(n<=0){
    console.log("你传入的数据有误")
    return
  }//加上对n的判断
    var sum=0
    for(var i=1;i<=n;i++){
      sum+=i
    }
    return sum
  }
  var sum=sumN(100)
  var result=sumN(5)
  console.log(sum)
  console.log(`1~5的和是${result}`)
  </script>
</body>
</html>